package com.fuyq.spring04;

import com.fuyq.demospringbootstarter.Hello;
import com.fuyq.spring04.beans.Klass;
import com.fuyq.spring04.beans.School;
import com.fuyq.spring04.beans.Student1;
import com.fuyq.spring04.beans.order.Order;
import com.fuyq.spring04.beans.order.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

@SpringBootApplication
public class Spring04Application {

    //Java bean方式
    @Autowired
    Order order;

    //注解方式
    @Autowired
    ProductService productService;

    public static void main(String[] args) {
        SpringApplication.run(Spring04Application.class, args);
    }

    //读取XML方式
    @Bean
    public void answer1(){
        //xml配置
        ApplicationContext bean1 = new FileSystemXmlApplicationContext("classpath:bean1.xml");
        Student1 student1 = bean1.getBean("student1", Student1.class);
        System.out.println(student1);
        student1.print();

        ApplicationContext bean2 = new ClassPathXmlApplicationContext("bean1.xml");
        Student1 student11 = bean2.getBean("student1", Student1.class);
        System.out.println(student11);
        student11.print();

        Klass klass = bean2.getBean("klass" ,Klass.class);
        klass.dong();

        School school = bean2.getBean("school", School.class);
        school.ding();

        order.print();

        productService.print();
    }

    //自定义starter
    @Autowired
    Hello hello;

    @Bean
    public void answer2(){
        System.out.println("----------------------自定义starter-------------------------");
        hello.say();
    }

}
